#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

struct man{
    string id;
    int virtue;
    int talent;
    int total;
    man(string id,int virtue,int talent,int total):id(id),virtue(virtue),talent(talent),total(total){}
};

bool cmp(man a,man b){
    if(a.total!=b.total){return a.total>b.total;}
    if(a.virtue!=b.virtue){return a.virtue>b.virtue;}
    return a.id<b.id;
}

int N,L,H;
vector<man>sages,noble,fool,rest;
int main(){
    //freopen("in.txt","r",stdin);
    scanf("%d %d %d",&N,&L,&H);
    string id;int virtue,talent;
    for(int i=0;i<N;i++){
        cin>>id;
        scanf("%d %d",&virtue,&talent);
        if(virtue<L || talent<L){continue;}
        else if(virtue>=H && talent>=H){sages.push_back(man{id,virtue,talent,virtue+talent});}
        else if(virtue>=H && talent<H){noble.push_back(man{id,virtue,talent,virtue+talent});}
        else if(virtue<H && talent<H && virtue>=talent){fool.push_back(man{id,virtue,talent,virtue+talent});}
        else {rest.push_back(man{id,virtue,talent,virtue+talent});}
    }
    printf("%d\n",sages.size()+noble.size()+fool.size()+rest.size());
    sort(sages.begin(),sages.end(),cmp);
    sort(noble.begin(),noble.end(),cmp);
    sort(fool.begin(),fool.end(),cmp);
    sort(rest.begin(),rest.end(),cmp);
    for(int i=0;i<sages.size();i++){
        cout<<sages[i].id;
        printf(" %d %d\n",sages[i].virtue,sages[i].talent);
    }
    for(int i=0;i<noble.size();i++){
        cout<<noble[i].id;
        printf(" %d %d\n",noble[i].virtue,noble[i].talent);
    }
    for(int i=0;i<fool.size();i++){
        cout<<fool[i].id;
        printf(" %d %d\n",fool[i].virtue,fool[i].talent);
    }
    for(int i=0;i<rest.size();i++){
        cout<<rest[i].id;
        printf(" %d %d\n",rest[i].virtue,rest[i].talent);
    }
}
